package com.dagr.wordboxoid.content;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import android.content.res.AssetManager;

public class WordCardDatabase {

	private WordCardDatabase() {
	}

	public static List<WordCard> findWordCards(AssetManager assetManager, String fileName) {
		try {
			BufferedReader reader = new BufferedReader(new InputStreamReader(assetManager.open(fileName)));

			List<WordCard> result = new ArrayList<WordCard>();
			for (String line = reader.readLine(); line != null && line.trim().length() > 0; line = reader.readLine()) {
				String[] tokens = line.split("\\t", 2);
				String side1 = tokens[0];
				String side2 = tokens[1];

				result.add(new WordCard.Builder().side1(side1).side2(side2).build());
			}

			return result;
		} catch (IOException e) {
			throw new RuntimeException("unable to find word cards for '" + fileName + "'", e);
		}
	}

}
